package com.yuan;

import com.alibaba.excel.EasyExcel;
import com.yuan.mapper.ZhcxmxMapper;
import com.yuan.黄鹏.ZuiZhongBjmx;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 *  @author 雨安
 *  类名： HuangPengZuiZhongApplication
 *  创建时间：2024/4/18
 */
@SpringBootTest
public class HuangPengZuiZhongApplication {
    @Autowired
    private ZhcxmxMapper zhcxmxMapper;


    @Test
    void haha(){
        List<String> firmList = zhcxmxMapper.selectAllFirmName();

        for (int i = 0; i < firmList.size(); i++) {
            //判断企业名不为null
            if (firmList.get(i)!=null){

                //通过分组后生成的每一个excel该有的记录
                List<ZuiZhongBjmx> zzList = zhcxmxMapper.selectAllOfFirm(" and bj.house_name = '" + firmList.get(i) + "'" +"and bj.bjtype != '区间超速'");

                //遍历集合
                for (int j = 0; j < zzList.size(); j++) {
                    //判断遍历的数据车牌不为null
                    if (zzList.get(j).getCarNo()!=null){
                        //创建条件字符串
                        String condition = "";
                        //判断类型不为null
                        if (zzList.get(j).getBjtype()!=null){
                            condition += " and bj.bjtype = '" + zzList.get(j).getBjtype() +"'";
                        }
                        //判断企业不为null
                        if (zzList.get(j).getHouseName()!=null){
                            condition += " and bj.house_name like '%" + zzList.get(j).getHouseName() +"%'";
                        }
                        //判断车牌号不为null
                        if (zzList.get(j).getCarNo()!=null){
                            condition += " and bj.car_no = '" +zzList.get(j).getCarNo() +"'";
                        }
                        //给当前数据记录设置总数
                        Integer count = zhcxmxMapper.selectCarCount(condition);
                        //将数据匹配给当前记录
                        if (count!=null && count!=0){
                            zzList.get(j).setFirmdriverjg( zzList.get(j).getBjtype() + count);
                            System.out.println("我设置的公司名：" + zzList.get(j).getHouseName() + "我设置的车牌号：" + zzList.get(j).getCarNo() + "我设置的次数：" + zzList.get(j).getFirmdriverjg());
                        }
                    }//判断当前记录不为null

                }// for j
                System.out.println("当前集合的数据：" + zzList);
                /********************此处是生成excel代码************************/
                String fileName = "D:\\黄鹏excel处理\\生成文件地址\\"+firmList.get(i)+"24.4.8-4.14周违章.xlsx";

                //表头字体颜色map 1为user中索引位置
                Map<Integer,Short> colorMap=new HashMap<>();

                colorMap.put(1, IndexedColors.BLUE.index);

                EasyExcel.write(fileName, ZuiZhongBjmx.class).sheet("安全报警明细").doWrite(zzList);

                /******************************************/

            }//判断当前遍历的企业名不为null  1 2019  2 2020

        }// for i结束

    }



}
